<?php
global $_W;
		$set = $this->module['config'];
		load()->model('mc');

		$list = pdo_fetch("SELECT * FROM ".tablename('cjwyzq_rank')." where uniacid ='{$_W['uniacid']}'");
		

		$count_sql = 'SELECT COUNT(DISTINCT openid) AS count FROM ' .tablename('cjwyzq_player') . ' WHERE uniacid = :uniacid ORDER BY max_score DESC';
		$count_map = $all_map = $rank_map = array(':uniacid'=>intval($_W['uniacid']));
		$count = pdo_fetch($count_sql, $count_map);
		
		if (intval($count) > 10) {
			$all_sql = 'SELECT * FROM ' .tablename('cjwyzq_player') . ' WHERE uniacid = :uniacid AND LIMIT 10 ORDER BY max_score DESC';
		} else {
			$all_sql = 'SELECT * FROM ' .tablename('cjwyzq_player') . ' WHERE uniacid = :uniacid ORDER BY max_score DESC';
		} 
		$scores = pdo_fetchall($all_sql, $all_map);
		foreach ($scores as $k => &$v) {
			$v['user_info'] = mc_fetch($v['openid']);
		}

		$my_sql = 'SELECT * FROM ' . tablename('cjwyzq_player') . ' WHERE uniacid = :uniacid AND openid = :openid';
		$my_map = array(':uniacid'=>$_W['uniacid'], ':openid'=>$_W['openid']);
		$myscore = pdo_fetch($my_sql, $my_map);
		
		if ($myscore) {
			$myscore['user_info'] = mc_fetch($myscore['openid']);
			$rank_sql = 'SELECT COUNT(DISTINCT openid) AS rank FROM ' . tablename('cjwyzq_player') . ' WHERE uniacid = :uniacid AND max_score > ' . $myscore['max_score'] . ' ORDER BY max_score DESC';
			$rank = pdo_fetch($rank_sql, $rank_map);
		} else {
			$myscore['user_info'] = mc_fetch($_W['openid']);
			$myscore['max_score'] = '无';
			$rank = '无';
		}
		
		include $this->template('rank');